<?php
set_include_path(
  SITE_ROOT_PATH
  . PATH_SEPARATOR . SS_ROOT_PATH
  . PATH_SEPARATOR . SS_ROOT_PATH.DIRECTORY_SEPARATOR.'lib'
  . PATH_SEPARATOR . SITE_ROOT_PATH.DIRECTORY_SEPARATOR.'lib'
  . PATH_SEPARATOR . get_include_path());
define('SS_CLI_MODE',(!$_SERVER['DOCUMENT_ROOT']));

require_once 'spyc/spyc.php';
require_once('ss/core/ss_core.php');
require_once('site/core/site_core.php');

//$default=new ss_core_serverConfig('default.config',SS_ROOT_PATH.DIRECTORY_SEPARATOR,SS_CLI_MODE);
//die(print_r(class_exists('site_core_config')?'yes':'no',true));
$ss=new site_core_config($config.'.config',SITE_ROOT_PATH.DIRECTORY_SEPARATOR,SS_CLI_MODE);
$server=new ss_core_serverConfig('slipstream.config',SS_ROOT_PATH.DIRECTORY_SEPARATOR,SS_CLI_MODE);
$server->merge(new ss_core_serverConfig('default.config',SS_ROOT_PATH.DIRECTORY_SEPARATOR,SS_CLI_MODE));
$ss->merge($server);
//die(print_r($ss,true));
if($ss['error']['firephp']['active'] && !SS_CLI_MODE){
	require_once('FirePHPCore/FirePHP.class.php');
	require_once('FirePHPCore/fb.php');
	require_once('ss/error/ss_error_firephp.php');
	$firephp = FirePHP::getInstance(true);
	
	$firephp->registerErrorHandler($throwErrorExceptions=true);
	$firephp->registerExceptionHandler();
	$firephp->registerAssertionHandler( $convertAssertionErrorsToExceptions=true, $throwAssertionExceptions=false);
	
	$options = array('maxObjectDepth' => 1,
	                 'maxArrayDepth' => 4,
	                 'useNativeJsonEncode' => true,
	                 'includeLineNumbers' => true);
	$firephp->setOptions($options);
	FB::setEnabled(true);
	error_reporting(E_ALL | E_STRICT);
	ss_error::info('Firephp logging enabled');
} elseif($ss['error']['file']['active']) {
	require_once('ss/error/ss_error_file.php');
	file_put_contents(SITE_ROOT_PATH.DIRECTORY_SEPARATOR.'log'.DIRECTORY_SEPARATOR.ss_error::$log,"Debug log:\n\n");
	ss_error::info('File logging enabled');
} else {
	require_once('ss/error/ss_error_dummy.php');
	ss_error::info('Logging disabled');
}
ss_error::log('Setting up spl');
if($ss['doctrine']['active']){
	if($ss['doctrine']['compiled']){
		if(file_exists($_file=SS_ROOT_PATH.'/comp/'.$ss['doctrine']['version'].'.compiled.php')){
			ss_error::log('Compiled version found');
			require_once($_file);
		} else {
			require_once($ss['doctrine']['version'].'/Doctrine.php');
		}
	} else {
	require_once($ss['doctrine']['version'].'/Doctrine.php');
	}
	spl_autoload_register(array('Doctrine', 'autoload'));
}
require_once('ss/core/ss_core_file.php');
	ss_error::log('Adding Slipsream autoloader');
spl_autoload_register(array('ss_core_file','autoload'));
//print_r(spl_autoload_functions());
ss_error::info('Bootstrap finished');
?>